package com.cn.web.user.controller;

import com.cn.annoation.Logs;
import com.cn.group.GroupDO;
import com.cn.msg.ResultMsg;
import com.cn.page.PageVo;
import com.cn.web.user.service.GroupService;
import com.cn.web.user.vo.GroupSearch;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * description: GroupController <br>
 * date: 23.5.8 14:23 <br>
 * author: cn_yaojin <br>
 * version: 1.0 <br>
 */
@RestController
@Api(tags = "用户中心--用户分组")
@Slf4j
@RequestMapping(value = "admin/group")
public class GroupController {

    @Autowired
    private GroupService groupService;

    @ApiOperation(value = "列表")
    @PostMapping(value = "page")
    public ResultMsg<PageInfo<GroupDO>> page(
            @RequestBody PageVo<GroupSearch> pageVo
    ) {
        return ResultMsg.builder().setData(this.groupService.page(pageVo));
    }

    @ApiOperation(value = "列表")
    @GetMapping(value = "list")
    public ResultMsg<List<GroupDO>> list(
    ) {
        return ResultMsg.builder().setData(this.groupService.list(null));
    }

    @ApiOperation(value = "编辑")
    @Logs(value = "编辑", desc = "用户分组")
    @PostMapping(value = "edit")
    public ResultMsg edit(
            @RequestBody GroupDO info
    ) {
        this.groupService.edit(info);
        return ResultMsg.builder();
    }

    @ApiOperation(value = "删除")
    @Logs(value = "删除", desc = "用户分组")
    @GetMapping(value = "del")
    public ResultMsg del(
            @ApiParam(name = "id") @RequestParam String id
    ) {
        this.groupService.del(id);
        return ResultMsg.builder();
    }

}
